/** layuiAdmin.std-v1.2.1 LPPL License By http://www.layui.com/admin/ */
layui.define(['form', 'pkc', 'format', 'validator'], function (e) {
    var t = layui.$;
    var layform = layui.form;
    var pkc = layui.pkc;
    var format = layui.format;
    var setter = layui.setter;
    var validator = layui.validator;

    var newObj = {};
    var form = {
        local: null,
        reloadData: function () {
            var data = parent.datas;
            //赋值表单
            layform.val("fmapp", {
                parkingname: data.parkingname,
                parkingid: data.parkingid,
                exitname: data.exitname,
                signkey: data.signkey,
                status: data.status
            });
        },
        //监听事件
        initEvt: function () {
            layform.on("submit(LAY-user-front-submit)", function (fm) {
                form.local = fm;
                layer.confirm('需要保存数据吗？', {
                    icon: 3,
                    title: "提示"
                }, function (index) {
                    var data = form.getParame(form.local);
                    form.toolAction.edit(data);
                    layer.close(index);
                });
                return false;
            });
            t('#btnBack').click(function (e) {
                form.close();
                e.preventDefault();
            });
        },
        //初始化页面
        init: function () {
            form.initEvt();
            form.reloadData();
        },
        toolAction: {
            // 编辑
            edit: function (data) {
                data["id"] = parent.datas.id;
                return pkc.http.SendPost(data, 'psamcloud.boss.device.lane.update', function (ret) {
                    ret = JSON.parse(ret);
                    if (ret) {
                        if (ret.Status === "1") {
                            //success
                            layer.msg('操作成功');
                            form.close();
                            //重新加载数据
                            parent.reloadGrid(10, 1);
                        } else {
                            layer.alert(ret.Message);
                        }
                    }
                    layer.closeAll("loading");
                }, function (ret) {
                    layer.alert("网络异常.请稍后再试！");
                    layer.closeAll("loading");
                })
            }
        },
        //获取参数值
        getParame: function (fmData) {
            var data = {};
            data["parkingname"] = fmData.field.parkingname;
            data["parkingid"] = fmData.field.parkingid;
            data["exitname"] = fmData.field.exitname;
            data["signkey"] = fmData.field.signkey;
            data["status"] = parseInt(fmData.field.status);
            return data;
        },

        //关闭窗体
        close: function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        },
    }
    e("laneedit", {
        init: () => {
            form.init();
        }
    });
});